var e = require;
var t = module;
var o = exports;
var n;
function i(e, t) {
    return (i =
        Object.setPrototypeOf ||
        function (e, t) {
            return (e.__proto__ = t), e;
        })(e, t);
}
(o.__esModule = !0), (o.default = void 0);
var a = (function (e) {
    var t, o;
    function n() {
        var t;
        return ((t = e.call(this) || this).gameRecordShareBtn = null), (t.moreGamePortal = null), t;
    }
    (o = e), ((t = n).prototype = Object.create(o.prototype)), (t.prototype.constructor = t), i(t, o);
    var a = n.prototype;
    return (
        (a.init = function () {
            (this.env = window.wx),
                (this.info = (window.lplatform && lplatform.systemInfo) || this.env.getSystemInfoSync()),
                (this.bh = lplatform.cparam.bannerHeight || 170),
                (this.bw = lplatform.cparam.bannerWidth || Math.min(this.info.windowWidth, (16 * this.bh) / 9)),
                (this.gameRecorderManager = this.env.getGameRecorder()),
                this.createGameClub(),
                this.showShareMenu(),
                this.checkLogin();
        }),
        (a.initAD = function () {
            this.loadBanner(!1), this.loadInterstitial(!1), this.createRewardedVideo(!1);
        }),
        (a.checkLogin = function () {
            var e = this;
            e.env.checkSession({
                success: function success() {
                    e.logined = !0;
                },
                fail: function fail() {
                    e.env.login({
                        success: function success(t) {
                            t.code ? (e.logined = !0) : console.log("登录失败！" + t.errMsg);
                        }
                    });
                }
            });
        }),
        (a.loadInterstitial = function (e) {
            this.hideInterstitial(),
                this.insterstitialAd
                    ? this.insterstitialAd.load()
                    : ((this.insterstitialAd = this.env.createInterstitialAd({
                          adUnitId: lplatform.cparam.interstitialID
                      })),
                      this.insterstitialAd.onLoad(this.onInterstitialLoad.bind(this)),
                      this.insterstitialAd.onError(this.onInterstitialError.bind(this)),
                      this.insterstitialAd.onClose(this.onInterstitialClose.bind(this))),
                e && this.showInterstitial();
        }),
        (a.onInterstitialError = function () {}),
        (a.onInterstitialClose = function () {}),
        (a.showInterstitial = function () {
            var e = this;
            this.insterstitialAd
                ? this.insterstitialAd.show().catch(function (t) {
                      lplatform.plog("showInterstitial cache:" + JSON.stringify(t)), e.createMoreGamePortal(!0, !0);
                  })
                : this.loadInterstitial(!0),
                this.createNativeGridAd();
        }),
        (a.hideInterstitial = function () {
            this.insterstitialAd, this.nativeGridAd && this.nativeGridAd.hide();
        }),
        (a.createGridAd = function () {
            this.gridAd && this.gridAd.destroy();
            var e = this.info.windowWidth - 100,
                t = this.info.windowWidth / 2 - e / 2,
                o = this.info.windowHeight / 2 - e / 2;
            (this.gridAd = this.env.createGridAd({
                adUnitId: lplatform.cparam.gridID,
                adIntervals: 30,
                gridCount: 5,
                style: {left: t, top: o, width: e, opacity: 0.8}
            })),
                this.gridAd.show();
        }),
        (a.showGridAd = function () {
            this.gridAd ? this.gridAd.show() : this.createGridAd();
        }),
        (a.createNativeGridAd = function () {
            this.nativeGridAd && this.nativeGridAd.destroy();
            var e = this.info.windowWidth,
                t = this.info.windowWidth / 2 - e / 2;
            (this.nativeGridAd = wx.createCustomAd({
                adUnitId: lplatform.cparam.nativeID,
                style: {left: t, top: 0, width: e, fixed: !0}
            })),
                this.nativeGridAd.show();
        }),
        (a.showNativeGridAd = function () {
            this.nativeGridAd ? this.nativeGridAd.show() : this.createNativeGridAd();
        }),
        (a.createGameClub = function () {
            this.env.createGameClubButton({
                icon: "green",
                style: {
                    left: lplatform.cparam.gameClubLeft * lplatform.systemInfo.windowWidth,
                    top: lplatform.cparam.gameClubTop * lplatform.systemInfo.windowHeight,
                    width: 40,
                    height: 40
                }
            });
        }),
        (a.showShareMenu = function () {
            "function" == typeof this.env.showShareMenu &&
                this.env.showShareMenu({withShareTicket: !0, menus: ["shareAppMessage", "shareTimeline"]}),
                this.env.onShareAppMessage(function () {
                    return {
                        title: lplatform.cparam.shareAppTitle,
                        imageUrl: lplatform.uiEngine.getCanvas().toTempFilePathSync({destWidth: 500, destHeight: 400})
                    };
                });
        }),
        (a.shareAppMessage = function () {
            this.env.shareAppMessage({title: lplatform.cparam.shareAppTitle});
        }),
        (a.navigateToMiniProgram = function () {}),
        (a.shareMessageToFriend = function () {}),
        (a.showFavoriteGuide = function () {
            console.log("微信未实现showFavoriteGuide");
        }),
        (a.subscribeAppMsg = function () {
            this.env.subscribeAppMsg({
                tmplIds: lplatform.cparam.tmplIds,
                subscribe: !0,
                success: function success(e) {
                    console.log("----subscribeAppMsg----success", e);
                },
                fail: function fail(e) {
                    console.log("----subscribeAppMsg----fail", e);
                }
            });
        }),
        (a.sendMsgToOpenDataProject = function (e) {
            this.logined ? this.env.getOpenDataContext().postMessage(e) : this.checkLogin();
        }),
        (a.setUserCloudStorage = function (e) {
            this.sendMsgToOpenDataProject({name: "setUserCloudStorage", kvdata: e});
        }),
        (a.canRecord = function () {
            return (
                !(!this.gameRecorderManager || !this.gameRecorderManager.isFrameSupported()) ||
                (console.log("不支持录制游戏画面"), !1)
            );
        }),
        (a.startRecord = function (e) {
            if (this.canRecord()) {
                lplatform.plog("startRecord"),
                    (this.recordStartCb = e),
                    (this.videoPath = null),
                    this.gameRecorderManager.start({fps: 24, bitrate: 1e3, hookBgm: !1, duration: 30}),
                    this.gameRecorderManager.on("start", this.onGameRecordStart.bind(this)),
                    this.gameRecorderManager.on("error", this.onGameRecordError.bind(this)),
                    this.gameRecorderManager.on("stop", this.onGameRecordStop.bind(this));
                var t = this;
                this.env.onShow(function () {
                    lplatform.plog("startRecord this.env.onShow"), t.resumeRecord();
                }),
                    this.env.onHide(function () {
                        lplatform.plog("startRecord this.env.onHide"), t.pauseRecord();
                    });
            }
        }),
        (a.onGameRecordStart = function () {
            (this.gameRecordStartTime = Date.now()),
                this.recordStartCb && (this.recordStartCb(), (this.recordStartCb = null));
        }),
        (a.onGameRecordError = function (e) {
            lplatform.plog("onGameRecordError:" + JSON.stringify(e), "error");
        }),
        (a.onGameRecordStop = function () {
            lplatform.plog("onGameRecordStop this.recordStopCb:" + this.recordStopCb),
                (this.gameRecordStopTime = Date.now()),
                this.gameRecordStopTime - this.gameRecordStartTime > 4500
                    ? (this.videoPath = "res.videoPath")
                    : lplatform.plog("onGameRecordStop 实际录屏时间少于5秒就有可能分享失败"),
                this.recordStopCb && (this.recordStopCb(this.videoPath), (this.recordStopCb = null));
        }),
        (a.pauseRecord = function () {
            this.gameRecorderManager.pause();
        }),
        (a.resumeRecord = function () {
            this.gameRecorderManager.resume();
        }),
        (a.stopRecord = function (e) {
            this.canRecord() &&
                (lplatform.plog("stopRecord cb:" + e), (this.recordStopCb = e), this.gameRecorderManager.stop());
        }),
        (a.shareRecord = function () {
            this.shareAppMessage(null);
        }),
        (a.resetRecord = function () {
            this.stopRecord(), (this.videoPath = null);
        }),
        (a.shareInnerRecord = function () {}),
        (a.makeShareUI = function (e, t, o, n, i) {
            if (
                (void 0 === n && (n = 0),
                void 0 === i && (i = !1),
                lplatform.uiEngine.CreateShareK(
                    function () {
                        this.shareRecord(e, t);
                    }.bind(this),
                    function () {
                        t && t(), this.gameRecordShareBtn && this.gameRecordShareBtn.hide();
                    }.bind(this),
                    o,
                    n,
                    i
                ),
                !this.gameRecordShareBtn)
            ) {
                this.gameRecordShareBtn = this.env.createGameRecorderShareButton({
                    style: {
                        left:
                            lplatform.cparam.shareRecordBtnLeft * lplatform.systemInfo.windowWidth -
                            lplatform.systemInfo.windowWidth / 3.5,
                        top:
                            lplatform.cparam.shareRecordBtnTop * lplatform.systemInfo.windowHeight -
                            lplatform.cparam.shareRecordBtnHeight / 2,
                        height: lplatform.cparam.shareRecordBtnHeight,
                        color: "#ffffff",
                        textAlign: "center",
                        fontSize: 16,
                        borderRadius: 4,
                        iconMarginRight: 16,
                        paddingLeft: 1,
                        paddingRight: 30
                    },
                    text: "分享你的神操作",
                    share: {query: "a=1&b=2", bgm: "bgm.mp3", timeRange: [[0, 3e4]]}
                });
                var a = this;
                this.gameRecordShareBtn.onTap(function (e) {
                    console.error(JSON.stringify(e)), lplatform.uiEngine.closeToYou(), a.gameRecordShareBtn.hide();
                });
            }
            lplatform.cparam.showVideoShareBtn ? this.gameRecordShareBtn.show() : this.gameRecordShareBtn.hide();
        }),
        (a.showBanner = function () {
            this.hideBanner(),
                lplatform.labData.mainSwitch &&
                    (Math.random() <= lplatform.cparam.moreGameBannerPercent
                        ? this.createMoreGameBanner()
                        : this.bannerAd
                        ? this.bannerAd
                              .show()
                              .then(function () {})
                              .catch(function (e) {
                                  lplatform.plog(e);
                              })
                        : this.loadBanner(!0));
        }),
        (a.createMoreGameBanner = function () {
            if ("function" == typeof this.env.createGameBanner) {
                var e = Math.floor(Math.random() * lplatform.cparam.moreGameBannerAppId.length),
                    t = lplatform.cparam.moreGameBannerAppId[e];
                (this.btop = 0),
                    lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - 104),
                    this.moreGameBanner && this.moreGameBanner.destroy(),
                    (this.moreGameBanner = this.env.createGameBanner({
                        adUnitId: t,
                        style: {left: (this.info.windowWidth - 300) / 2, top: this.btop}
                    })),
                    this.moreGameBanner.show();
            }
        }),
        (a.createMoreGamePortal = function (e, t) {
            void 0 === e && (e = !1), void 0 === t && (t = !1);
        }),
        (a.goToGameOrGameList = function () {
            this.createMoreGamePortal(!0, !0);
        }),
        (a.httpRequest = function (e, t, o, n, i, a, r) {
            this.env.request({
                url: e,
                data: i,
                header: a,
                timeout: o,
                method: n,
                dataType: r,
                success: function success(e) {
                    t(null, e.data, JSON.stringify(e.data));
                },
                fail: function fail(e) {
                    t(e, null, null);
                }
            });
        }),
        n
    );
})(((n = e("PTT")) && n.__esModule ? n : {default: n}).default);
(o.default = a), (t.exports = o.default);
